import json
import time

from Monitor import monitor_symbol


def select_shizhi():
    # 读取 usdt.json 文件
    with open('usdt.json', 'r', encoding='utf-8') as file:
        data = json.load(file)

    # 筛选市值在 4 亿到 80 亿之间的数据
    filtered_data = [
        item for item in data
        if 100000000 <= item.get('shizhi', 0) <= 400000000
    ]

    # 打印筛选结果
    print("筛选结果（市值在 4 亿到 80 亿之间）:")
    rdata = []
    for item in filtered_data:
        print(item)
        rdata.append(item)

    try:
        config_file = 'select_min.json'
        with open(config_file, 'w', encoding='utf-8') as f:
            json.dump(rdata, f, ensure_ascii=False, indent=4)
    except Exception as e:
        print(f"保存币种列表出错: {e}")
    return rdata

def check_usdt():
    data = select_shizhi()
    rdata = []
    for item in data:
        symbol = item['symbol']
        isusdt = monitor_symbol(symbol + "USDT")
        if isusdt:
            rdata.append(item)
        try:
            config_file = 'select_usdt_min.json'
            with open(config_file, 'w', encoding='utf-8') as f:
                json.dump(rdata, f, ensure_ascii=False, indent=4)
        except Exception as e:
            print(f"保存币种列表出错: {e}")
        time.sleep(1)

check_usdt()